<admintpl file="header" />
<style type="text/css">
	.pic-list li {
		margin-bottom: 5px;
	}
	.label-td {
		position: relative;
	}
	.label-td .label-container {
		float: left;
		width: 93%;
		overflow: hidden;
		white-space: nowrap;
	}
	.label-td .label-select {
		float: right;
		font-size: 18px;
		display: inline-block;
		position: relative;
		padding-top: 10px;
	}
	.label-td .label-select:hover {
		color: #5bc0de;
	}
	.label-td .label-container span {
		display: inline-block;
		width: 80px;
		height: 30px;
		line-height: 30px;
		border: 1px solid #5bc0de;
		border-radius: 10px;
		text-align: center;
		margin-right: 10px;
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
	}
	.select_area {
		margin-top: 30px;
		width: 40%!important;
	}

	.city_span {
		border: 1px solid #ffbd4d;
		padding: 5px 10px;
		margin-right: 5px;
		border-radius: 20px;
		width: auto!important;
	}
</style>
</head>
<body>
	<div class="wrap js-check-wrap">
		<ul class="nav nav-tabs">
			<li><a href="{:U('Service/Adminindex/index')}" target="_self">服务商列表</a></li>
			<li class="active"><a href="">编辑服务商</a></li>
		</ul>
		<form action="{:U('Service/Adminindex/edit_sp', ['id' => $sp_info['id']])}" method="post" class="form-horizontal js-ajax-forms" enctype="multipart/form-data">
			<div class="row-fluid">
				<div class="span9">
					<table class="table table-bordered">
						<input type="hidden" name="sp_info[id]" value="{$sp_info.id}">
						<tr>
							<th width="80">分类</th>
							<td>
								<select name="cate[]" multiple="multiple">
									<volist name="categorys" id="vo">
										<option value="{$vo.id}" <?php echo in_array($vo['id'], $sp_info['categorys']) ? 'selected' : ''?>>{$vo.name}</option>
									</volist>
								</select>
								<div>windows：按住 Ctrl 按钮来选择多个选项,Mac：按住 command 按钮来选择多个选项</div>
							</td>
						</tr>
						<tr>
							<th width="80">覆盖城市</th>
							<td>
								<input id="sp_city_ids" type="hidden" name="sp_info[city_ids]" value="{$sp_info.city_ids}">
								<volist name="sp_info.city_names" id="vo">
									<span id="{$key}" class="city_span">{$vo}</span>
								</volist>
								<button type="button" id="select_city_btn" style="float: right;">选择城市</button>
								<span style="color: red;display: inline-block;margin-top: 6px;">点击城市名称删除</span>
							</td>
						</tr>
						<tr>
							<th>名称</th>
							<td>
								<input type="hidden" name="sp_info[id]" value="{$sp_info.id}">
								<input type="text" style="width: 400px;" name="sp_info[company_name]" required value="{$sp_info.company_name}" placeholder="请输入名称"/>
								<span class="form-required">*</span>
							</td>
						</tr>
						<tr>
							<th>全称</th>
							<td>
								<input type="text" style="width: 400px;" name="sp_info[company_full_name]" required value="{$sp_info.company_full_name}" placeholder="请输入全称"/>
								<span class="form-required">*</span>
							</td>
						</tr>
						<tr>
							<th>公司规模</th>
							<td>
								<select name="sp_info[company_scale]">
									<option value="0" {$sp_info['company_scale'] == 0 ? 'selected' : ''}>不明确</option>
									<option value="20" {$sp_info['company_scale'] <= 20 && $sp_info['company_scale'] > 0 ? 'selected' : ''}>1 ~ 20</option>
									<option value="100" {$sp_info['company_scale'] <= 100 && $sp_info['company_scale'] > 20 ? 'selected' : ''}>20 ~ 100</option>
									<option value="500" {$sp_info['company_scale'] <= 500 && $sp_info['company_scale'] > 100 ? 'selected' : ''}>100 ~ 500</option>
									<option value="1000" {$sp_info['company_scale'] <= 1000 && $sp_info['company_scale'] > 500 ? 'selected' : ''}>500 ~ 1000</option>
									<option value="5000" {$sp_info['company_scale'] <= 5000 && $sp_info['company_scale'] > 1000 ? 'selected' : ''}>1000 ~ 5000</option>
									<option value="99999" {$sp_info['company_scale'] > 5000 ? 'selected' : ''}>5000以上</option>
								</select>
							</td>
						</tr>
						<tr>
							<th>成立时间</th>
							<td>
								<input type="date" name="sp_info[established_time]" style="width: 400px" value="{$sp_info.established_time}" placeholder="请输入成立时间">
							</td>
						</tr>
						<tr>
							<th>公司地址</th>
							<td>
								<input type="text" name="sp_info[company_addr]" style="width: 400px" value="{$sp_info.company_addr}" placeholder="请输入公司地址">
							</td>
						</tr>
						<tr>
							<th>一句话简介</th>
							<td>
								<input type="text" name="sp_info[sign]" style="width: 400px" value="{$sp_info.sign}" placeholder="请输入一句话简介">
							</td>
						</tr>
						<tr>
							<th>详细介绍</th>
							<td>
								<textarea name="sp_info[company_desc]" style="width: 401px;height: 200px;" placeholder="请输入简介">{$sp_info.company_desc}</textarea>
							</td>
						</tr>

						<tr>
							<th>服务介绍</th>
							<td>
								<script type="text/plain" id="service_desc" name="sp_info[service_desc]">{$sp_info.service_desc}</script>
							</td>
						</tr>
						<tr>
							<th>合作收益</th>
							<td>
								<script type="text/plain" id="benifit" name="sp_info[benifit]">{$sp_info.benifit}</script>
							</td>
						</tr>
						<tr>
							<th>合作条件</th>
							<td>
								<script type="text/plain" id="condition" name="sp_info[condition]">{$sp_info.condition}</script>
							</td>
						</tr>
					</table>
				</div>
				<div class="span3">
					<table class="table table-bordered">
						<tr>
							<td><b>logo</b></td>
						</tr>
						<tr>
							<td>
								<div style="text-align: center;">
									<input type="hidden" name="sp_info[logo]" id="thumb" value="{$sp_info.logo|default=''}">
									<a href="javascript:upload_one_image('图片上传','#thumb');">
										<if condition="empty($sp_info['logo'])">
											<img src="__TMPL__Public/assets/images/default-thumbnail.png" id="thumb-preview" width="135" style="cursor: hand"/>
										<else />
											<img src="{:sp_get_image_preview_url($sp_info['logo'])}" id="thumb-preview" width="135" style="cursor: hand"/>
										</if>
									</a>
									<input type="button" class="btn btn-small" onclick="$('#thumb-preview').attr('src','__TMPL__Public/assets/images/default-thumbnail.png');$('#thumb').val('');return false;" value="取消图片">
								</div>
							</td>
						</tr>
						<tr>
							<td><b>状态</b></td>
						</tr>
						<tr>
							<td>
								<input type="radio" name="sp_info[status]" value="1" <?php echo $sp_info['status'] == 1 ? 'checked' : ''?>> 正常
								<input type="radio" name="sp_info[status]" value="2" <?php echo $sp_info['status'] == 2 ? 'checked' : ''?>> 下线
							</td>
						</tr>

						<if condition="!empty($sp_info)">
							<tr>
								<td><b>其他信息</b></td>
							</tr>
							<tr>
								<td>
									<a href="{:U('Adminindex/sp_financing_list',array('id' => $sp_info['id']))}">融资</a>
								</td>
							</tr>
							<tr>
								<td>
									<a href="{:U('Adminindex/sp_member_list',array('id' => $sp_info['id']))}">团队成员</a>
								</td>
							</tr>
							<tr>
								<td>
									<a href="{:U('Adminindex/sp_project_list',array('id' => $sp_info['id']))}">项目</a>
								</td>
							</tr>
							<tr>
								<td>
									<a href="{:U('Adminindex/sp_link_list',array('id' => $sp_info['id']))}">链接</a>
								</td>
							</tr>
						</if>
					</table>
				</div>
			</div>
			<div class="form-actions">
				<button class="btn btn-primary js-ajax-submit" type="submit">提交</button>
				<a class="btn" href="{:U('Service/Adminindex/index')}">返回</a>
			</div>
		</form>
	</div>

	<!--城市选择-->
	<div id="areaInfo" style="display: none;text-align: center">
		<input id="city_id" type="hidden" name="city_id">
	</div>

	<script type="text/javascript" src="__PUBLIC__/js/common.js"></script>
	<script type="text/javascript">
		//编辑器路径定义
		var editorURL = GV.WEB_ROOT;
	</script>
	<script type="text/javascript" src="__PUBLIC__/js/ueditor/ueditor.config.js"></script>
	<script type="text/javascript" src="__PUBLIC__/js/ueditor/ueditor.all.min.js"></script>
	<script type="text/javascript" src="__PUBLIC__/js/layer/layer_1.js"></script>
	<script type="text/javascript" src="__PUBLIC__/js/notify.js"></script>
	<script type="text/javascript" src="__PUBLIC__/js/area.js"></script>
	<script>
        var area = {$area};
        area = eval(area);
        $(function () {
            // 地址选择select的初始化
            initArea(2);
        })
	</script>
	<script type="text/javascript">

		$(function() {

		    $(document).delegate('.city_span', 'click', function () {
				var _this 		= $(this);
				var id 			= $(this).attr('id');
				var city_ids 	= $('#sp_city_ids').val();
                var arr 		= city_ids.split(',');
				layer.confirm("确定删除", {
                    btn: ['确定','取消']
				}, function(index) {
					_this.remove();
					var arr_index = arr.indexOf(id);
					console.log(arr_index);
					if (arr_index > -1) {
                        $('#sp_city_ids').val(arr.splice(arr_index + 1, 1));
					}
                    layer.close(index);
                })
            });
		    
		    $('#select_city_btn').click(function () {
                layer.open({
					type 	: 1,
                    title 	: "选择城市",
                    area 	: ['50%', '50%'],
                    btn 	: ['确定', '取消'],
                    content	: $('#areaInfo'),
                    yes 	: function (index, layerC) {
					    if (isAreaInfoValid()) {
                            var sp_city_ids 	= $('#sp_city_ids').val();
                            arr 				= sp_city_ids.split(',');
                            var select_city_id 	= $('#areaInfo #city_id').val();
                            var select_city_name= $('#city').find("option:selected").text();
                            if ($.inArray(select_city_id, arr) < 0) {
                                $('#select_city_btn').before("<span id='" + select_city_id + "' class='city_span'>" + select_city_name + "</span>");
                                arr.push(select_city_id);
                                $('#sp_city_ids').val(arr.join(','));
                            }
						}
					    layer.close(index);
                    }
                });
            });

			/////---------------------
			Wind.use('validate', 'ajaxForm', 'artDialog', function() {
				//javascript

				//编辑器
				editorcontent_service_desc = new baidu.editor.ui.Editor();
                editorcontent_service_desc.render('service_desc');
				try {
                    editorcontent_service_desc.sync();
				} catch (err) {
				}
				//增加编辑器验证规则
				jQuery.validator.addMethod('editorcontent_service_desc', function() {
					try {
                        editorcontent_service_desc.sync();
					} catch (err) {
					}
					;
					return editorcontent_service_desc.hasContents();
				});

                editorcontent_benifit = new baidu.editor.ui.Editor();
                editorcontent_benifit.render('benifit');
                try {
                    editorcontent_benifit.sync();
                } catch (err) {
                }
                //增加编辑器验证规则
                jQuery.validator.addMethod('editorcontent_benifit', function() {
                    try {
                        editorcontent_benifit.sync();
                    } catch (err) {
                    }
                    ;
                    return editorcontent_benifit.hasContents();
                });

                editorcontent_condition = new baidu.editor.ui.Editor();
                editorcontent_condition.render('condition');
                try {
                    editorcontent_condition.sync();
                } catch (err) {
                }
                //增加编辑器验证规则
                jQuery.validator.addMethod('editorcontent_condition', function() {
                    try {
                        editorcontent_condition.sync();
                    } catch (err) {
                    }
                    ;
                    return editorcontent_condition.hasContents();
                });
				var form = $('form.js-ajax-forms');
				//ie处理placeholder提交问题
				if ($.browser && $.browser.msie) {
					form.find('[placeholder]').each(function() {
						var input = $(this);
						if (input.val() == input.attr('placeholder')) {
							input.val('');
						}
					});
				}
				//表单验证开始
				form.validate({
					//是否在获取焦点时验证
					onfocusout : false,
					//是否在敲击键盘时验证
					onkeyup : false,
					//当鼠标掉级时验证
					onclick : false,
					//验证错误
					showErrors : function(errorMap, errorArr) {
						//errorMap {'name':'错误信息'}
						//errorArr [{'message':'错误信息',element:({})}]
						try {
							$(errorArr[0].element).focus();
							art.dialog({
								id : 'error',
								icon : 'error',
								lock : true,
								fixed : true,
								background : "#CCCCCC",
								opacity : 0,
								content : errorArr[0].message,
								cancelVal : '确定',
								cancel : function() {
									$(errorArr[0].element).focus();
								}
							});
						} catch (err) {
						}
					},
					//验证规则
					rules : {
						'sp_info[established_time]' : {
							required : 1
						},
						'sp_info[company_name]' : {
                            required : 1
						},
                        'sp_info[company_full_name]' : {
                            required : 1
                        },
					},
					//验证未通过提示消息
					messages : {
						'sp_info[established_time]' : {
							required : '请输入正确的时间'
						},
                        'sp_info[company_name]' : {
                            required : '请输入名称'
                        },
                        'sp_info[company_full_name]' : {
                            required : '请输入全称'
                        },
					},
					//给未通过验证的元素加效果,闪烁等
					highlight : false,
					//是否在获取焦点时验证
					onfocusout : false,
					//验证通过，提交表单
					submitHandler : function(forms) {
						$(forms).ajaxSubmit({
							url : form.attr('action'), //按钮上是否自定义提交地址(多按钮情况)
							dataType : 'json',
							beforeSubmit : function(arr, $form, options) {
							},
							success : function(data, statusText, xhr, $form) {
								if (data.status) {
									setCookie("refersh_time", 1);
									//添加成功
									Wind.use("artDialog", function() {
										art.dialog({
											id : "succeed",
											icon : "succeed",
											fixed : true,
											lock : true,
											background : "#CCCCCC",
											opacity : 0,
											content : data.info,
											button : [ {
												name : '继续编辑？',
												callback : function() {
													reloadPage(window);
													return true;
												},
												focus : true
											}, {
												name : '返回列表页',
												callback : function() {
													location = "{:U('Service/Adminindex/index')}";
													return true;
												}
											} ]
										});
									});
								} else {
									artdialog_alert(data.info);
								}
							}
						});
					}
				});
			});
		});
	</script>
</body>
</html>